/*
 * Copyright (c) 2021 Talkweb Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "ohos_types.h"
#include "ohos_init.h"
#include "cmsis_os2.h"



/***
 *定时器1 回调函数
 *\param[in]   arg  回调参数
 *
 *
 */
void Timer1Callback(void *arg)
{
    uint32 te = (uint32)arg;
    printf("This is Timer1Callback:%d!\r\n", te);
}

/***
 *定时器2 回调函数
 *\param[in]   arg  回调参数
 *
 *
 */
void Timer2Callback(void *arg)
{
    uint32 te = (uint32)arg;
    printf("This is Timer2Callback:%d!\r\n", te);
}

/**
 * 创建定时器
 */
static void TimerExample(void)
{
    osTimerId_t timerId1, timerId2;
    uint32 delay;
    osStatus_t status;
    uint32 timer1Exec, timer2Exec;
    timer1Exec = 1U;
    // 创建一个定时器
    timerId1 = osTimerNew(Timer1Callback, osTimerPeriodic, timer1Exec, NULL);
    if (timerId1 != NULL)
    {
        delay = 100U;
        // 启动定时器
        status = osTimerStart(timerId1, delay);
        if (status != osOK)
        {
            printf("Falied to start timer1!\n");
        }
    }

    timer2Exec = 100U;
    timerId2 = osTimerNew(Timer2Callback, osTimerPeriodic, timer2Exec, NULL);
    if (timerId2 != NULL)
    {
        delay = 300U;
        status = osTimerStart(timerId2, delay);
        if (status != osOK)
        {
            printf("Falied to start timer2!\n");
        }
    }
}

APP_FEATURE_INIT(TimerExample);
